<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<script src="__JS__/highcharts-9.1.2.js"></script>
	<body class="pear-container">
		
		<div class="layui-card">
			<div class="layui-card-body">
				{if $month == 0}
				<table id="dataTable" class="layui-table layui-table-box" lay-filter="dataTable">
					<thead>
					<tr>
						{if isMobile()}
					    <th lay-data="{field:'name', width:'100',unresize:'true',align:'center',fixed:'left'}">
						{else/}
						<th lay-data="{field:'name', width:'100',unresize:'true',align:'center'}">
						{/if}
						名称</th>
					    {for start="1" end="$length+1"}
					    <th lay-data="{field:'month{$i}',width:'100',unresize:'true',align:'center'}"><a href="{:U('Collect/sale',['year'=>$year,'month'=>$i])}">{$i}月</a></th>
					    {/for}
						<th lay-data="{field:'total', width:'120',unresize:'true',align:'center'}">汇总</th>
					</tr>
					</thead>
					<tbody>
					<tr>
					  <td>新增客户</td>
					  {php}
					  $a=0;
					  for($i=1;$i<=$length;$i++){
						echo '<td>'.$T[$i]['dow'].' 人</td>';
						$a+=$T[$i]['dow'];
					  }
					  echo '<td>'.$a.' 人</td>';
					  {/php}
					</tr>
					<tr>
					    <td>下单客户</td>
					    {php}
					    $a=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.$T[$i]['cus'].' 人</td>';
					      $a+=$T[$i]['cus'];
					    }
					    echo '<td>'.$a.' 人</td>';
					    {/php}
					</tr>
					<tr>
					    <td>采购单量</td>
					    {php}
					    $a=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.$T[$i]['count'].' 单</td>';
					      $a+=$T[$i]['count'];
					    }
					    echo '<td>'.$a.' 单</td>';
					    {/php}
					</tr>
					<tr>
					    <td>大货匹数</td>
					    {php}
					    $a=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.$T[$i]['roll'].' 匹</td>';
					      $a+=$T[$i]['roll'];
					    }
					    echo '<td>'.$a.' 匹</td>';
					    {/php}
					</tr>
					<tr>
					    <td>销售额</td>
					    {php}
					    $year_total=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.price_one($T[$i]['total']).'</td>';
					      $year_total+=$T[$i]['total'];
					    }
					    echo '<td>'.price_one($year_total).'</td>';
					    {/php}
					</tr>
					{if $sensitive==1}
					<tr>
					    <td>进货成本</td>
					    {php}
					    $a=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.price_one($T[$i]['cost']).'</td>';
					      $a+=$T[$i]['cost'];
					    }
					    echo '<td>'.price_one($a).'</td>';
					    {/php}
					</tr>
					<tr>
					    <td>毛利润</td>
					    {php}
					    $year_profit=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td><a href="'.U('bill.main/index',['year'=>$year,'month'=>$i,'type'=>1]).'">'.price_one($T[$i]['g_profit']).'</a></td>';
					      $year_profit+=$T[$i]['g_profit'];
					    }
					    echo '<td>'.price_one($year_profit).'</td>';
					    {/php}
					</tr>
					<tr>
					    <td>开销支出</td>
					    {php}
					    $year_invest=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td><a href="'.U('bill.main/index',['year'=>$year,'month'=>$i,'type'=>0]).'">'.price_one($T[$i]['invest']).'</a></td>';
					      $year_invest+=$T[$i]['invest'];
					    }
					    echo '<td>'.price_one($year_invest).'</td>';
					    {/php}
					</tr>
					{/if}
					<tr>
					    <td>净利润</td>
					    {php}
					    $year_profit=0;
					    for($i=1;$i<=$length;$i++){
					      echo '<td>'.price_one($T[$i]['n_profit']).'</td>';
					      $year_profit+=$T[$i]['n_profit'];
					    }
					    echo '<td>'.price_one($year_profit).'</td>';
					    {/php}
					</tr>
					{if $sensitive==1}
					<tr>
					    <td>毛利率</td>
					    {php}
					    $a=0;
					    for($i=1;$i<=$length;$i++){
							echo '<td>';
							if($T[$i]['total']>0){
								echo price_one($T[$i]['g_profit']/$T[$i]['total']*100);
							}else{
								echo 0;
							}
							echo ' %</td>';
						}
						echo '<td>';
						if($year_profit==0 && $year_total==0){
						  echo 0;
						}else{
						  echo price_one($year_profit/$year_total*100);
						}
						echo ' %</td>';
					    {/php}
					</tr>
					{/if}
					</tbody>
				</table>
				{/if}

				<div class="layui-card" id="collect1"></div>
				<div class="layui-card" id="collect2"></div>
				
				{if $month gt 0}
				
				<table id="dataTable" class="layui-table" lay-filter="dataTable">
					<thead>
					<tr>
						<th lay-data="{field:'v1', width:'20%',align:'center'}">日期</th>
						<th lay-data="{field:'v2', width:'10%',align:'center'}">销售额</th>
						<th lay-data="{field:'v3', width:'10%',align:'center'}">新增客户</th>
						<th lay-data="{field:'v4', width:'10%',align:'center'}">大货数</th>
						<th lay-data="{field:'v5', width:'10%',align:'center'}">订单量</th>
						<th lay-data="{field:'v6', width:'10%',align:'center'}">进货成本</th>
						<th lay-data="{field:'v7', width:'10%',align:'center'}">当日开销</th>
						<th lay-data="{field:'v8', width:'20%',align:'center'}">净利润</th>
					</tr>
					</thead>
					<tbody>
						{volist name="T" id="v"}
						<tr>
						    <td><a href="{:U('deal.Main/index',['year'=>$year,'month'=>$month,'day'=>$key,'cost'=>1])}" target="_blank">{$year}年{$month}月{$key}日</a></td>
						    <td class="right-price">{$v.total|price_one}</td>
						    <td>{$v.dow} 人</td>
							<td>{$v.roll} 匹</td>
						    <td>{$v.count} 单</td>
						    <td class="right-price">{$v.cost|price_one}</td>
							<td class="right-price">{$v.invest|price_one}</td>
						    <td class="right-price">{$v.n_profit|price_one}</td>
						</tr>
						{/volist}
					</tbody>
					</table>
				{/if}
			</div>
		</div>
		<script type="text/html" id="toolbar">
			{if $month==0}
			<button class="pear-btn pear-btn-md" id="year-list">
			  {$year}年
			  <i class="layui-icon layui-icon-down layui-font-12"></i>
			</button>
			<button class="pear-btn pear-btn-md" id="month-list">
			  月份
			  <i class="layui-icon layui-icon-down layui-font-12"></i>
			</button>
			{/if}
		</script>
		
        <script>
        layui.use(['jquery','common','mycomm','table','dropdown'], function() {
            let $ = layui.jquery;
			let common = layui.common;
			let mycomm = layui.mycomm;
			let table = layui.table;
			let dropdown = layui.dropdown;
			
			table.init('dataTable', {
				even:true,
				limit:31,
				toolbar: '#toolbar',
			});
			
			
			{if $month == 0}
			dropdown.render({
				elem: '#year-list',
				data: {$year_list|raw},
				id: 'year-list',
				//菜单被点击的事件
				click: function(obj){
				  window.location=obj.url;
				}
			});
			dropdown.render({
				elem: '#month-list',
				data: {$month_list|raw},
				id: 'month-list',
				//菜单被点击的事件
				click: function(obj){
					mycomm.tool_pop(obj.url,'{$year}年'+obj.title+'销售情况',0.9);
				}
			});
			{/if}
			
        })	
    </script>
	<script type="text/javascript">
	var chart = Highcharts.chart('collect1', {
	    chart: {
	        type: 'areaspline'
	    },
	    title: {
	        {php}
	        if($month<=0){
	            echo "text: '".$year."年度销售情况表'";
	        }else{
	            echo "text: '".$year."年".$month."月销售情况表'";
	        }
	        {/php}
	    },
	    legend: {
	        layout: 'vertical',
	        align: 'left',
	        verticalAlign: 'top',
	        x: 150,
	        y: 100,
	        floating: true,
	        borderWidth: 1,
	        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
	    },
	    xAxis: {
	        {php}
	        if($month<=0){
	            echo "categories: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],";
	        }else{
	            $str="categories: [";
	            for($i=1;$i<=$length;$i++){
	                $str.= $i.',';
	            }
	            echo substr($str,0,-1).'],';
	        }
	        {/php}
	    },
	    yAxis: {
	        title: {
	            text: ''
	        }
	    },
	    tooltip: {
	        shared: true,
	        valueSuffix: '元'
	    },
	    plotOptions: {
	        areaspline: {
	            fillOpacity: 0.7
	        }
	    },
	    series: [{
	        name: '销售额',
	        data: [{$total}]
	    },{
	        name: '净利润',
	        data: [{$n_profit}]
	    }
	    ]
	});
	
	var chart = Highcharts.chart('collect2',{
	    chart: {
	        type: 'column'
	    },
	    title: {
	        {php}
	        if($month<=0){
	            echo "text: '".$year."年度下单情况'";
	        }else{
	            echo "text: '".$year."年".$month."月下单情况'";
	        }
	        {/php}
	    },
	    subtitle: {
	        text: ''
	    },
	    xAxis: {
	        {php}
	        if($month<=0){
	            echo "categories: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],";
	        }else{
	            $str="categories: [";
	            for($i=1;$i<=$length;$i++){
	                $str.= $i.',';
	            }
	            echo substr($str,0,-1).'],';
	        }
	        {/php}
	        crosshair: true
	    },
	    yAxis: {
	        min: 0,
	        title: {
	            text: '下单情况'
	        }
	    },
	    tooltip: {
	        // head + 每个 point + footer 拼接成完整的 table
	        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
	        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
	        '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
	        footerFormat: '</table>',
	        shared: true,
	        useHTML: true
	    },
	    plotOptions: {
	        column: {
	            borderWidth: 0
	        }
	    },
	    series: [{
	        name: '新增客户',
	        data: [{$dow}]
	    }, {
	        name: '下单客户',
	        data: [{$cus}]
	    }, {
	        name: '采购单量',
	        data: [{$count}]
	    }, {
	        name: '采购大货',
	        data: [{$roll}]
	    }]
	});
	</script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
